package com.fenghongzhang.day004;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {
    private RecyclerView rv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        rv = (RecyclerView) findViewById(R.id.rv);

        MyLinearManager myLinearManager = new MyLinearManager(this);
        rv.setLayoutManager(myLinearManager);

        List<VideoBean> list = new ArrayList<>();
        for (int i = 0; i < TestVideoUrl.videoUrls.length; i++) {
            list.add(new VideoBean());
        }
        MyAdapter myAdapter = new MyAdapter(R.layout.rv_layout, list);
        rv.setAdapter(myAdapter);

        rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                switch (newState){
                    case RecyclerView.SCROLL_STATE_IDLE:
                        RecyclerView.LayoutManager layoutManager = rv.getLayoutManager();
                        StandardGSYVideoPlayer viewById = layoutManager.getChildAt(0).findViewById(R.id.gsy_player);
                        viewById.startPlayLogic();
                        break;
                }
            }
        });

    }
}
